package com.mediacloud.app.newsmodule.activity;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.media.MediaMetadata;
import android.media.session.PlaybackState;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.ColorInt;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.chinamcloud.audioserver.APSLifecycleKit;
import com.chinamcloud.audioserver.MusicEntity;
import com.chinamcloud.report.ReportKit;
import com.eventTrack.TXReportManager;
import com.jaeger.library.StatusBarUtil;
import com.lzf.easyfloat.interfaces.OnPermissionResult;
import com.lzf.easyfloat.permission.PermissionUtils;
import com.mediacloud.app.assembly.util.FunKt;
import com.mediacloud.app.assembly.util.Utility;
import com.mediacloud.app.assembly.views.ImageButtonX;
import com.mediacloud.app.model.interfaces.DataInvokeCallBack;
import com.mediacloud.app.model.interfaces.IPermissionsAgree;
import com.mediacloud.app.model.interfaces.PermissionUtil;
import com.mediacloud.app.model.news.ArticleItem;
import com.mediacloud.app.model.news.ArticleItemReciver;
import com.mediacloud.app.model.news.CatalogItem;
import com.mediacloud.app.model.news.ReadDataReciver;
import com.mediacloud.app.newsmodule.R;
import com.mediacloud.app.newsmodule.activity.audio.IndicatorSeekBar;
import com.mediacloud.app.newsmodule.pay.NormalPayUtil;
import com.mediacloud.app.newsmodule.pay.PaidContentListener;
import com.mediacloud.app.newsmodule.pay.PaidMetas;
import com.mediacloud.app.newsmodule.utils.AppfacBuyEnableUtils;
import com.mediacloud.app.newsmodule.utils.KillMusicUtils;
import com.mediacloud.app.newsmodule.utils.LoginUtils;
import com.mediacloud.app.newsmodule.utils.NewsDetailInvoker;
import com.mediacloud.app.newsmodule.utils.ReadStatusInvoker;
import com.mediacloud.app.newsmodule.utils.TopicListDataInvoker;
import com.mediacloud.app.reslib.analysis.AnalysisUtils;
import com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig;
import com.mediacloud.app.reslib.enums.ListStyle;
import com.mediacloud.app.reslib.enums.XKey;
import com.tencent.mmkv.MMKV;
import com.utils.SystemServiceManager;
import com.utils.UriTool;
import com.utils.read.AudioFloatManager;

import org.greenrobot.eventbus.EventBus;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

import tv.danmaku.ijk.media.player.IMediaPlayer;

/**
 * 音频点直播 的基类 主要是处理了布局  分享等功能
 *
 * @author x
 */
@SuppressWarnings("ALL")
public abstract class BaseAudioActivityHalf extends StyleSetActivity implements OnClickListener {
    private TextView showMoreDes;
    protected TextView tvAuthor;
    protected TextView tvPlayCount;
    protected TextView tvPublishData;
    private TextView titleView;
    protected ImageView logoView;
    private View summaryLayout;//简介view
    protected View mErrorView;
    protected TextView emptyTipsText;
    protected IndicatorSeekBar seekbar;
    protected ImageButtonX loopModeBtn;
    protected ImageView speedIv;

    protected CheckBox togglePauseBtn;
    protected TextView streamLineBtn;
    protected TextView audioDesTitle;
    protected TextView audioDes;
    protected ImageView summaryOpen;
    protected LinearLayout broccoliLayout;

    //收费收听需要隐藏的布局
    protected RelativeLayout playPanelLayout;
    protected TextView payAmount;
    protected NormalPayUtil normalPayUtil;
    protected TextView tvVipPayHowmuch;


    protected boolean isAutoPlay = true;
    protected String cdnEncrypt;
    protected CatalogItem catalogItem;

    boolean loadedImg;
    protected boolean openLikeBtn;
    protected final int TYPE_NO_NETWORK = 0;// 無網絡
    protected final int TYPE_NOT_WIFI = 1; //不是WIFI
    protected Dialog dialog;
    protected int dialogType = -1;

    protected TopicListDataInvoker topicListDataInvoker;
    protected ReadStatusInvoker readStatusInvoker;
    protected int pageNum = 1;
    protected int pageSize = 15;

    protected APSLifecycleKit apsKit;
    protected boolean isAPSPrepared = false;
    protected MusicEntity musicEntity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // getPermission();

        initView();
        boolean isLeftImgMode = ListStyle.TotoalStyle.LEFT_IMAGE.equals(AppFactoryGlobalConfig.getAppServerConfigInfo(this).getContent_list());
        if (broccoliLayout != null) {
            if (isLeftImgMode) {
                for (int i = 0; i < 3; i++) {
                    broccoliLayout.addView(LayoutInflater.from(this).inflate(R.layout.layout_broccoli21, null));
                }
            } else {
                for (int i = 0; i < 3; i++) {
                    broccoliLayout.addView(LayoutInflater.from(this).inflate(R.layout.layout_broccoli22, null));
                }
            }
        }
        StatusBarUtil.setLightMode(this);

        getArgs();

        setTitle("");
        titleView.setText(articleItem.getTitle());

        intPayViews();
        if (articleItem != null) readStatus();
        isAutoPlay = MMKV.defaultMMKV().decodeBool(XKey.AUTO_PLAY, false);
        initAPS();
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        AppfacBuyEnableUtils.refresh(this, false);
        showPageTransition();
        if (summaryOpen != null)
            summaryOpen.setOnClickListener(v -> {

                if (showMoreDes.isSelected()) {
                    audioDes.setMaxLines(1);
                    summaryOpen.animate().rotationBy(-180).start();
                } else {
                    audioDes.setMaxLines(Integer.MAX_VALUE);
                    summaryOpen.animate().rotationBy(180).start();
                }
                showMoreDes.setSelected(!showMoreDes.isSelected());
            });
    }

    private void initAPS() {
        apsKit = new APSLifecycleKit(this, "" + articleItem.getId(), seekbar, new APSLifecycleKit.APSCallback() {
            @Override
            public void onServiceConnected(@Nullable ComponentName name, @Nullable IBinder iBinder) {
                super.onServiceConnected(name, iBinder);
                isAPSPrepared = true;
                if (musicEntity != null && apsKit.getData() != null && apsKit.getData().size() == 0) {
                    apsKit.setData(musicEntity);
                }
            }

            @Override
            public void onBufferingUpdate(@Nullable IMediaPlayer mediaPlayer, int percent) {
                super.onBufferingUpdate(mediaPlayer, percent);
            }

            @Override
            public void onCompletion(@Nullable IMediaPlayer mediaPlayer) {
                super.onCompletion(mediaPlayer);
            }

            @Override
            public void onMetadataChanged(@Nullable MediaMetadata metadata) {
                super.onMetadataChanged(metadata);
            }

            @Override
            public void onPlaybackStateChanged(@Nullable PlaybackState state) {
                super.onPlaybackStateChanged(state);
                switch (state.getState()) {

                    case PlaybackState.STATE_NONE://无任何状态
                    case PlaybackState.STATE_STOPPED:
                    case PlaybackState.STATE_PAUSED:
                        togglePauseBtn.setChecked(false);
                        break;
                    case PlaybackState.STATE_PLAYING:
                        togglePauseBtn.setChecked(true);
                        break;
                    case PlaybackState.STATE_SKIPPING_TO_NEXT://下一首
                        break;
                    case PlaybackState.STATE_SKIPPING_TO_PREVIOUS://上一首
                        break;
                    case PlaybackState.STATE_FAST_FORWARDING://快进
                        break;
                    case PlaybackState.STATE_REWINDING://快退
                        break;
                    case PlaybackState.STATE_ERROR:
                        com.utils.ToastUtil.showToastCenter(BaseAudioActivityHalf.this, "出错了", Toast.LENGTH_SHORT);
                        break;
                }
            }

            @Override
            public void onPrepared(@Nullable IMediaPlayer mediaPlayer) {
                super.onPrepared(mediaPlayer);
            }

        });
        apsKit.setAutoPlay(isAutoPlay);
        if (isAutoPlay) {
            KillMusicUtils.hideReadNewsWin();
        }
    }

    private void intPayViews() {
        payAmount = Utility.findViewById(mRootView, R.id.pay_how_much);
        tvVipPayHowmuch = Utility.findViewById(mRootView, R.id.tv_vip_pay_how_much);
        GradientDrawable gradientDrawable = (GradientDrawable) tvVipPayHowmuch.getBackground();
        gradientDrawable.setCornerRadius(90);
        gradientDrawable.setGradientRadius(90);

        payAmount.setBackground(gradientDrawable);
        tvVipPayHowmuch.setBackground(gradientDrawable);
        playPanelLayout = Utility.findViewById(mRootView, R.id.playPanelLayout);
        normalPayUtil = new NormalPayUtil(this, catalogItem, new NormalPayUtil.Others() {

            @NotNull
            @Override
            public TextView getVipPayView() {
                return tvVipPayHowmuch;
            }

            @NotNull
            @Override
            public String operation() {
                return getString(R.string.pay_buy_audio);
            }

            @Override
            public List<View> payView() {
                List<View> payView = new ArrayList<>();
                payView.add(payAmount);
                return payView;
            }

            @Override
            public List<View> paidView() {
                List<View> paidView = new ArrayList<>();
                paidView.add(playPanelLayout);
                List<View> otherListPaidView = getPaidViews();
                if (otherListPaidView != null && otherListPaidView.size() != 0) {
                    paidView.addAll(otherListPaidView);
                }
                return paidView;
            }

            @NotNull
            @Override
            public TextView openView() {
                return payAmount;
            }
        }, new PaidContentListener() {
            @Override
            public void onPaidContent(@NotNull final PaidMetas meta) {
                onPaidAudio(meta.getAudio());
            }
        }, true);

    }


    protected boolean needLoadTopBgSkin() {
        return false;
    }


    @SuppressWarnings("deprecation")
    protected void initView() {
        summaryOpen = Utility.findViewById(mRootView, R.id.arrowIco);
        showMoreDes = Utility.findViewById(mRootView, R.id.showMoreDes);
        tvPlayCount = Utility.findViewById(mRootView, R.id.tvPlayCount);
        tvAuthor = Utility.findViewById(mRootView, R.id.tvAuthor);
        tvPublishData = Utility.findViewById(mRootView, R.id.tvPublishData);

        broccoliLayout = Utility.findViewById(mRootView, R.id.broccoliLayout);
        titleView = Utility.findViewById(mRootView, R.id.titleView);
        logoView = Utility.findViewById(mRootView, R.id.image_toggle_bg);
        seekbar = Utility.findViewById(mRootView, R.id.seekbar);
        //  view = findViewById(R.id.tv_pre);
        loopModeBtn = Utility.findViewById(mRootView, R.id.loopModeBtn);
        speedIv = Utility.findViewById(mRootView, R.id.speedIv);
        speedIv.setOnClickListener(null);
        togglePauseBtn = Utility.findViewById(mRootView, R.id.togglePauseBtn);
        streamLineBtn = Utility.findViewById(mRootView, R.id.streamLineBtn);
        audioDesTitle = Utility.findViewById(mRootView, R.id.audioDesTitle);
        audioDes = Utility.findViewById(mRootView, R.id.audioDes);
        summaryLayout = Utility.findViewById(mRootView, R.id.cl_product);
        mErrorView = Utility.findViewById(mRootView, R.id.error_view);
        emptyTipsText = Utility.findViewById(mRootView, R.id.emptyTipsText);
        ImageView imagNowork = mErrorView.findViewById(R.id.image_loading);
        Drawable drawable = ContextCompat.getDrawable(this, R.drawable.net_not_give_force);
        String network = AppFactoryGlobalConfig.getAppServerConfigInfo(this).getNetwork();
        FunKt.load(imagNowork, network, drawable);

        mTitileBar.setBackgroundColor(Color.parseColor("#FAFAFA"));
        mTitlebar_MoreContainer.setVisibility(View.GONE);
        togglePauseBtn.setOnClickListener(this);

        if (streamLineBtn != null) {
            streamLineBtn.setOnClickListener(this);
        }
    }

    @Override
    public int getStatusBarColor() {
        return Color.parseColor("#FAFAFA");
    }


    protected void getArgs() {
        Uri uriData = getIntent().getData();
        if (uriData != null) {
            isFromH5OpenToReStart =UriTool.INSTANCE.isFromH5OpenToReStart(this,uriData);
            String articleid = uriData.getQueryParameter("articleid");
            String title = uriData.getQueryParameter("title");
            String cname = uriData.getQueryParameter("cname");
            String tag = uriData.getQueryParameter("tag");
            catalogItem = new CatalogItem();
            catalogItem.setCatname(cname);
            articleItem = new ArticleItem();
            try {
                articleItem.setTitle(title);
                if (!TextUtils.isEmpty(articleid))
                    articleItem.setId(Long.valueOf(articleid));
            } catch (Exception e) {
            }
        } else {
            articleItem = getIntent().getParcelableExtra("data");
            catalogItem = getIntent().getParcelableExtra("catalog");
        }
        try {
            if (catalogItem == null)
                catalogItem = new CatalogItem();
            catalogItem.setCatalog_type(getIntent().getStringExtra("category"));
            catalogItem.setCatid(getIntent().getStringExtra("navigate_id"));
            if (articleItem == null) {
                articleItem = new ArticleItem();
                articleItem.setId(Long.parseLong(getIntent().getStringExtra("article_id")));
                articleItem.setSummary(getIntent().getStringExtra("summary"));
                articleItem.setTitle(getIntent().getStringExtra("title"));
                articleItem.setUrl(getIntent().getStringExtra("url"));
                articleItem.setIsAdvertisement(getIntent().getIntExtra("isAdvertisement", 0));
                articleItem.setIsBarrage(getIntent().getIntExtra("isBarrage", 0));
                articleItem.setReferSourceID(getIntent().getStringExtra("ReferSourceID"));
                articleItem.setIsComment(getIntent().getStringExtra("isComment"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    /**
     * 获取组件的相关数据
     */
//    protected void getComponentData() {
//        ViewGroup componentLinear = findViewById(R.id.linear_layout_relative_component);
//        if (componentLinear != null) {
//            topicListDataInvoker = new TopicListDataInvoker(new DataInvokeCallBack<TopicDetailDataReciver>() {
//                @Override
//                public void success(TopicDetailDataReciver data) {
//                    Log.w(TAG, "success");
//                    componentLinear.removeAllViews();
//                    NewsDetailComponentUtils.addComponentList(componentLinear, data.componentItems, articleItem, BaseAudioActivityHalf.this, getSupportFragmentManager(), 1);
//
//                }
//
//                @Override
//                public void fault(Object data) {
//                    Log.e(TAG, "fault");
//                }
//            });
//            if (articleItem.getCid() > 0) {
//                topicListDataInvoker.getTopicDetailById(String.valueOf(articleItem.getCid()), pageNum, pageSize);
//            } else {
//                topicListDataInvoker.getArticleById(String.valueOf(articleItem.getId()), UserInfo.getUserInfo(this).getUserid(), articleItem.getParentId(), pageNum, pageSize);
//            }
//        }
//    }


    /**
     * 进入登录
     *
     * @param context
     */
    protected void intoLogin(Context context) {
//        ToastUtil.show(context, R.string.please_login);
        LoginUtils.request_source="音频";
        LoginUtils.invokeLogin(context);
    }

    @Override
    public int getLayoutResID() {
        return R.layout.activity_audio_player_half;
    }


    public void onClick(View v) {
        if (v.getId() == R.id.togglePauseBtn) {
            KillMusicUtils.hideReadNewsWin();
            if (isCloseNetQuest) {
                checkNetType();
                return;
            }
            onToggleClick();
            apsKit.toggle();
        } else if (v.getId() == R.id.streamLineBtn) {
            showStreamLine();
        }
    }

    public void onToggleClick() {

    }

    abstract void showStreamLine();


    protected Drawable tintDrawable(int drawableId, @ColorInt int color) {
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), drawableId);
        Drawable bitmapDrawable = new BitmapDrawable(getResources(), bmp);
        bitmapDrawable = Utility.tintDrawable(color, bitmapDrawable.mutate());
        return bitmapDrawable;
    }

    protected int getPaletteColor() {
        return Color.RED;
    }

    //开启语音播报
    private void startReadNews() {
        if (TextUtils.isEmpty(apsKit.getUrl())) {
            return;
        }
        TXReportManager.getInstance().voice_read(articleItem);
        articleItem.setText_audio_url(apsKit.getUrl());
        if(apsKit.isTaskPlaying()){
            AudioFloatManager.Companion.getInstance(this).setArticle(articleItem);
            AudioFloatManager.Companion.getInstance(this).setCatalogItem(catalogItem);
        }
        AudioFloatManager.Companion.getInstance(this).show();

    }

    protected final void sendShowFloaWinMsg() {
        if (!apsKit.isTaskPlaying()) {
            realFinish();
            return;
        }
        if (PermissionUtils.checkPermission(this)) {
            startReadNews();
            realFinish();
        }else{
            AudioFloatManager.showPermissionAsk(this, new OnPermissionResult() {
                @Override
                public void permissionResult(boolean isOpen) {
                    if (isOpen) {
                        startReadNews();
                    }
                    realFinish();
                }
            });
        }

       /* final Intent intent = new Intent();
        intent.setAction(AudioBackgroundBroad.ShowAction);
        intent.putExtra("data", articleItem);
        intent.putExtra("catalog", catalogItem);
        final Context context = getApplicationContext();
        mRootView.postDelayed(new Runnable() {
            @Override
            public void run() {
                LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
            }
        }, 350);*/
    }

//    protected final void sendHideFloaWinMsg() {
//        Intent intent = new Intent();
//        intent.setAction(AudioBackgroundBroad.HideAction);
//        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
//    }

    /**
     * 这里真实的去finish() 用于
     * 处理退出当前也没的时候，需要申请悬浮窗权限的时候，不能真实的调用finish()否则取不到权限申请的结果
     */
    public void realFinish() {
        super.finish();
    }

    @Override
    protected void onDestroy() {
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
        if (readStatusInvoker != null) {
            readStatusInvoker.destory();
            readStatusInvoker = null;
        }
//        if (commentDialogFram != null) {
//            commentDialogFram.dismiss();
//            commentDialogFram.destory();
//        }
        super.onDestroy();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        if (requestCode == MemberActivity.REQUEST_CODE && intent != null
                && intent.getBooleanExtra(MemberActivity.REQUEST_KEY, false)) {
            normalPayUtil.judgeShowPayView(articleItem);
        }
    }


    /**
     * 走添加阅读数接口
     */
    private void readStatus() {
        readStatusInvoker = new ReadStatusInvoker(new DataInvokeCallBack<ReadDataReciver>() {
            @Override
            public void success(ReadDataReciver data) {
                AnalysisUtils.readsAnalysis(getApplicationContext(), articleItem, data.virtualIncrement);
            }

            @Override
            public void fault(Object data) {
                AnalysisUtils.readsAnalysis(getApplicationContext(), articleItem, AnalysisUtils.DefaultVirtualIncrement);
            }
        });
        readStatusInvoker.readStatistics(articleItem.getId() + "", 1);
    }


    /**
     * 检查网络状态
     */
    @Override
    public void checkNetType() {
        PermissionUtil.INSTANCE.invokeNetWorkPermission(this, new IPermissionsAgree() {
            @Override
            public void onAgree() {
                extracted();

            }

            @Override
            public void onRefuse() {

            }

            @Override
            public void hasPermissions() {
                extracted();

            }
        });
    }

    private void extracted() {
        ConnectivityManager cm = SystemServiceManager.getConnectivityManager(this);
        NetworkInfo networkInfo = cm.getActiveNetworkInfo();
        //有網絡
        if (networkInfo != null && networkInfo.isAvailable()) {
            hasNetWork = true;
            //目前變成手機流量狀態
            if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                netChangeStopPlay();
                showNoticeDialogs(TYPE_NOT_WIFI);
                //目前變成手機WiFi狀態
            } else if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                netChangePlay();
            }
        } else {
            //沒網絡的時候
            hasNetWork = false;
            netChangeStopPlay();
            noNetwork();
            showNoticeDialogs(TYPE_NO_NETWORK);
        }
    }

    /**
     * 子类重写
     */
    public void netChangeStopPlay() {
        if (apsKit.isPlaying()) {
            apsKit.toggle();
        }
    }

    /**
     * 子类重写
     */
    public void netChangePlay() {

    }

    /**
     * 网络状态改变时候的Dialog
     *
     * @param noticType
     */
    private boolean isCloseNetQuest;

    void showNoticeDialogs(int noticType) {

        if (dialog != null && dialogType == noticType && dialog.isShowing()) {
            return;
        }
        dialogType = noticType;
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View contentView = inflater.inflate(R.layout.audio_notic, null);
        TextView title = contentView.findViewById(R.id.audio_notice_title);
        TextView btn1 = contentView.findViewById(R.id.audio_notice_btn1);
        TextView btn2 = contentView.findViewById(R.id.audio_notice_btn2);
        dialog = null;
        dialog = new Dialog(this, R.style.loadingDialogStyle);
        dialog.setContentView(contentView);
        // 无网络提示
        if (noticType == TYPE_NO_NETWORK) {
            title.setText(R.string.audio_notice_noNetWork);
            btn1.setText(R.string.audio_notice_Got_it);
            btn2.setText(R.string.audio_notice_Go_check);
            btn1.setOnClickListener(v -> {
                isCloseNetQuest = true;
                if (dialog.isShowing()) {
                    dialog.dismiss();
                }
            });
            btn2.setOnClickListener(v -> {
                isCloseNetQuest = false;
                Intent intent = null;
                intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
                startActivity(intent);
                if (dialog.isShowing()) {
                    dialog.dismiss();
                }
            });
            // Wifi变流量
        } else if (noticType == TYPE_NOT_WIFI) {
            title.setText(R.string.audio_notice_isNotWifi);
            btn1.setText(R.string.audio_notice_goON);
            btn2.setText(R.string.audio_notice_close);
            btn1.setOnClickListener(v -> {
                isCloseNetQuest = false;
                netChangePlay();
                if (dialog.isShowing()) {
                    dialog.dismiss();
                }
            });
            btn2.setOnClickListener(v -> {
                isCloseNetQuest = true;
                if (dialog.isShowing()) {
                    dialog.dismiss();
                }
            });
        }
        dialog.show();
    }

    public void setCl_lyaoutVisiable(int show) {
        if (summaryLayout != null) {

            summaryLayout.setVisibility(show);
        }
    }

    abstract protected void onPaidAudio(String audio);


    /**
     * 获取其余支付后需要显示的View
     */
    protected List<View> getPaidViews() {
        return null;
    }


    public static void isChartRoom(Context context, String id, ChatRoomListener listener) {
        NewsDetailInvoker newsDetailInvoker = new NewsDetailInvoker(new DataInvokeCallBack<ArticleItemReciver>() {
            @Override
            public void success(ArticleItemReciver data) {
                if (data != null) {
                    if (data.chatRoom != null && data.chatRoom.isOpen) {
                        String author = "";
                        if (data.articleItem != null && data.articleItem.Author != null) {
                            author = data.articleItem.Author;
                        }
                        listener.chartRoom(true, author);
                    } else {
                        listener.chartRoom(false, null);
                    }
                } else {
                    listener.chartRoom(false, null);
                }
            }

            @Override
            public void fault(Object data) {
                listener.chartRoom(false, null);
            }
        });

        newsDetailInvoker.getArticleById("" + id, "");
    }

    @Override
    public void finish() {
        ReportKit.INSTANCE.escalationArticleTime();
        super.finish();
    }

    public interface ChatRoomListener {
        void chartRoom(boolean chart, String author);
    }
}